package com.yykj.message.center.server.controller;

import com.yykj.message.center.client.dto.DrugOrderMessageBodyDTO;
import com.yykj.message.center.client.dto.PrescriptionMessageBodyDTO;
import com.yykj.message.center.client.dto.TDMQMessageSendResult;
import com.yykj.message.center.client.dto.pay.DrugOrderCancelMessageBodyDTO;
import com.yykj.message.center.client.enums.OrderType;
import com.yykj.message.center.server.service.TencentTDMQMessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.pulsar.client.api.PulsarClientException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/api/tdmq/message")
@Api(tags = "发送tdmq 消息")
@SuppressWarnings(value = "unchecked")
public class TencentTDMQController {

    @ApiOperation("发送支付成功消息")
    @PostMapping("/pay/success")
    public TDMQMessageSendResult sendOrderPaySuccessMessage(@RequestParam(name = "orderId") String orderId,
                                                            @RequestParam(name = "orderType") OrderType orderType) throws PulsarClientException {
        return messageService.sendOrderPaySuccessMessage(orderId, orderType);
    }

    @ApiOperation("发送订单结束消息")
    @PostMapping("/order/finish")
    public TDMQMessageSendResult sendOrderFinishMessage(@RequestParam(name = "orderId") String orderId,
                                                        @RequestParam(name = "orderType") OrderType orderType) throws PulsarClientException {
        return messageService.sendOrderFinishMessage(orderId,orderType);
    }


    @ApiModelProperty("发送处方消息--新建")
    @PostMapping("/prescription/created")
    public TDMQMessageSendResult sendPrescriptionCreatedMessage(@RequestBody PrescriptionMessageBodyDTO messageBodyDTO) throws PulsarClientException {
        return messageService.sendPrescriptionCreatedMessage(messageBodyDTO);
    }

    @ApiModelProperty("发送处方消息--状态变更")
    @PostMapping("/prescription/change")
    public TDMQMessageSendResult sendPrescriptionChangeMessage(@RequestBody PrescriptionMessageBodyDTO messageBodyDTO) throws PulsarClientException {
        return messageService.sendPrescriptionChangeMessage(messageBodyDTO);
    }

    @ApiModelProperty("发送处方药品下单消息")
    @PostMapping("/drug/order/created")
    public TDMQMessageSendResult sendDrugOrderMessage(@RequestBody DrugOrderMessageBodyDTO messageBodyDTO) throws PulsarClientException {
        return messageService.sendDrugOrderMessage(messageBodyDTO);
    }

    @ApiModelProperty("发送延迟取消订单消息")
    @PostMapping("/drug/order/cancelDrugOrder")
    public TDMQMessageSendResult sendCancelDrugOrderMessage(@RequestBody DrugOrderCancelMessageBodyDTO messageBodyDTO) throws PulsarClientException {
        return messageService.sendCancelDrugOrderMessage(messageBodyDTO);
    }

    private TencentTDMQMessageService messageService;

    @Autowired
    public void setMessageService(TencentTDMQMessageService messageService) {
        this.messageService = messageService;
    }
}
